﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using System.Drawing;

namespace System.Drawing.Imaging.Assist
{
    /// <summary>
    /// Inverse image processing
    /// </summary>
    internal class BPProcess : ImageProcessBase
    {
        /// <summary>
        /// init function
        /// </summary>
        /// <param name="image"></param>
        public BPProcess(Bitmap image) : base(image) { }

        /// <summary>
        /// Inverse image processing algorithms
        /// </summary>
        /// <returns></returns>
        public override Bitmap ProcessImage()
        {
            BitmapData bitmapdata = Source.LockBits(new Rectangle(new Point(0, 0), Source.Size),
                    ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            //RP algorithm: rgb
            for (int i = 0; i < bitmapdata.Height * bitmapdata.Width; i++)
                Marshal.WriteInt32(bitmapdata.Scan0, (i * 4), (int)((uint)0xFFFFFFFF -
                    Marshal.ReadInt32(bitmapdata.Scan0, (i * 4))));

            Source.UnlockBits(bitmapdata);

            return Source;
        }
    }
}
